package com.libbase.extension

import io.reactivex.rxjava3.core.Observable

data class CurAndPreData<T>(val current: T, val previous: T)

fun <T : Any> Observable<T>.previous(first: T): Observable<CurAndPreData<T>> {
    return scan(CurAndPreData(first, first)) { seed, value ->
        CurAndPreData(value, seed.current)
    }
}

fun <T : Any> Observable<T>.filterDuplicates(first: T): Observable<T> {
    return previous(first).filter {
        it.current != it.previous
    }.map {
        it.current
    }
}